package com.car.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.commons.core.model.Result;
import com.car.commons.core.util.JwtUtil;
import com.car.commons.web.util.WebUtil;
import com.car.order.entity.ServeOrderItem;
import com.car.order.entity.form.serveOrderItem.ServeOrderItemFindListForm;
import com.car.order.entity.form.serveOrderItem.ServeOrderItemFindPageForm;
import com.car.order.entity.form.serveOrderItem.ServeOrderItemInsertForm;
import com.car.order.entity.form.serveOrderItem.ServeOrderItemUpdateForm;
import com.car.commons.core.model.Result;
import io.jsonwebtoken.Jwt;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;

import org.springframework.web.bind.annotation.*;
import com.car.order.service.ServeOrderItemService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;

/**
 * @author 杜岷芫
 * @since 2024-08-29 10:20:36
 */
@RestController
@RequestMapping("/serveOrderItem")
@Api(tags = "服务订单项目")
public class ServeOrderItemController {

    @Autowired
    private ServeOrderItemService serveOrderItemService;

    /**
     * 分页查询
     *
     * @param form
     * @return
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/findPage")
    public Result findPage(@RequestBody ServeOrderItemFindPageForm form) {
        Page<ServeOrderItem> result = serveOrderItemService.findPage(form);
        return Result.getResult().setMsg("查询成功").setData(result);
    }

    /**
     * 列表查询
     *
     * @param form
     * @return
     */
    @ApiOperation(value = "列表查询")
    @PostMapping("/findList.md")
    public Result findList(@RequestBody ServeOrderItemFindListForm form) {
        List<ServeOrderItem> result = serveOrderItemService.findList(form);
        return Result.getResult().setMsg("查询成功").setData(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询详情")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        ServeOrderItem serveOrderItem = serveOrderItemService.findById(id);
        return Result.getResult().setMsg("查询成功").setData(serveOrderItem);
    }

    /**
     * 新增
     *
     * @param form
     * @return
     */
    @ApiOperation(value = "新增")
    @PostMapping
    public Result insert(@RequestBody ServeOrderItemInsertForm form) {
        ServeOrderItem serveOrderItem = serveOrderItemService.insert(form);
        return Result.getResult().setMsg("操作成功").setData(serveOrderItem);
    }

    /**
     * 修改
     *
     * @param form
     * @return
     */
    @ApiOperation(value = "修改")
    @PutMapping
    public Result update(@RequestBody ServeOrderItemUpdateForm form) {
        String token = WebUtil.getToken();
        Integer clerkId = JwtUtil.getClerkId(token);
        ServeOrderItem serveOrderItem = serveOrderItemService.update(form);
        return Result.getResult().setMsg("操作成功").setData(serveOrderItem);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        serveOrderItemService.delete(id);
        return Result.getResult().setMsg("操作成功");
    }

    /**
     * 完成进度
     */
    @ApiOperation(value = "完成进度")
    @GetMapping("/over/{id}.md")
    public Result over(@PathVariable("id") Integer id) {

        serveOrderItemService.over(id);
        return Result.getResult();
    }
}